<template>
  <div class="app-container">
    <el-input
      v-model="filterText"
      placeholder="请输入过滤条件..."
      style="margin-bottom: 30px"
    />

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
  </div>
</template>

<script>
import subject from "@/api/subject/subject"

export default {
  data() {
    return {
      filterText: "",
      data2: [],
      defaultProps: {
        children: "children",
        label: "title",
      },
    };
  },
  
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val);
    },
  },

  created() {
      this.list()
  },

  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.title.toLowerCase().indexOf(value) !== -1;
    },
    //显示课程列表方法
    list() {
        subject.getSubjectList()
        subject.getSubjectList()
        .then(res => {
            this.data2 = res.data.list
        })
        .catch(error => {
            console.log(error);
        })
    }
  }
};
</script>

